
window.pagination = {};
pagination = function(container) {
	this.element_ = $(container);
};

pagination.PAGE_TEMPLATE_ = '<div class="page-control"><ol class="page clrfix">\
		<li class="page-note"><span class="page-item mpg-gray">共<em>${recordCount}</em>条</span></li>\
        <li class="page-prev"><a class="page-item" href="javascript:;" hidefocus="true" data-pager-link="prev">&lsaquo;&nbsp;上一页</a></li>\
        {{each(idx,page) pages}}\
            {{if page.type == "page"}}\
            <li class="page-li"><a class="page-item" href="javascript:;" hidefocus="true" data-pager-pageno="${page.no}">${page.no}</a></li>\
            {{/if}}\
            {{if page.type == "curr"}}\
            <li class="page-current"><span class="page-item">${page.no}</span></li>\
            {{/if}}\
            {{if page.type == "omission"}}\
            <li class="page-note"><span class="page-item">...</span></li>\
            {{/if}}\
        {{/each}}\
        <li class="page-next"><a class="page-item" href="javascript:;" hidefocus="true" data-pager-link="next">下一页&nbsp;&rsaquo;</a></li>\
    </ol></div>';

pagination.EventType = {
	CHANGE: "pagechange"
};

pagination.prototype.pageSize_ = 20;

pagination.prototype.getPageSize = function() {
	return this.pageSize_;
};

pagination.prototype.setPageSize = function(pageSize) {
	this.pageSize_ = pageSize;
};

pagination.prototype.renderPager = function(totalNum, currentPage) {
	if (totalNum < this.pageSize_) {
		this.element_.html('<div class="page-control"><span class="ps">共' + totalNum + '条</span></div>');
	} else {
		this.element_.pager({
			recordCount: totalNum,
			dispNum: 3,
			currentPage: currentPage,
			pageSize: this.pageSize_,
			tmpl: pagination.PAGE_TEMPLATE_,
			on: {
				select: $.proxy(this.handlePagerSelect, this)
			}
		});
	}
};

pagination.prototype.handlePagerSelect = function(pageno) {
	$(this).trigger(new $.Event("pagechange", {
		pageNo: pageno-1
	}), {}, this);
};